import Dialog from ".";
import { observer } from "mobx-react";
import { Row, Col, Radio } from 'antd';
import { WeaFormItem, WeaInput, WeaSelect, WeaCheckbox, WeaBrowser, WeaTab, WeaLocaleProvider } from 'ecCom';
import OperatorSet from "../designer/path/OpreatorSet";
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class NodeModal extends React.Component {
    render() {
        const { store } = this.props;
        const { form } = store;
        const uuid = form.$('uuid').values();
        const nameField = form.$('name');
        const nodetype = form.$("nodeType");
        const operatortype = form.$('operatorType');
        const tablename = form.$('tablename');
        const tablekey = form.$('tablekey');
        const showfield = form.$('showfield');
        const isrecursion = form.$('isrecursion');
        const tablesup = form.$('tablesup');
        const relationtype = form.$('relationtype');
        const hrmresource = form.$('hrmresource');
        const hrmdepartment = form.$('hrmdepartment');
        const hrmsubcompany = form.$('hrmsubcompany');
        const rootids = form.$('rootids');
        const supnodefield = form.$('supnodefield');
        const nodefield = form.$('nodefield');
        const hreflink = form.$('hreflink');
        const hreflinkType = form.$('hreflinkType');
        const iscustom = form.$('iscustom');
        const reporttime = form.$('reporttime');
        const reporttimetype = form.$('reporttimetype');
        const reporttype = form.$('reporttype');
        const undotype = form.$('undotype');
        const isreject = form.$('isreject');
        const nodetypeOptions = [];
        if (uuid === "root") {
            nodetypeOptions.push({
                key: '0',
                title: getLabel('502714', '静态节点'),
            });

        } else if (store.parentNodeType && store.parentNodeType === '1') {
            nodetypeOptions.push({
                key: '1',
                title: getLabel('502715', '动态节点'),
            });
        } else {
            nodetypeOptions.push({
                key: '0',
                title: getLabel('502714', '静态节点'),
            });
            nodetypeOptions.push({
                key: '1',
                title: getLabel('502715', '动态节点'),
            });
            // nodetypeOptions.push({
            //     key: '2',
            //     title: getLabel('502716','子路径触发'),
            // });
        }
        const nodeTypeValue = nodetype.values();
        const operatorTypeValue = operatortype.values();
        const isDynamic = nodeTypeValue === "1";
        const isStatic = nodeTypeValue === "0";
        const isRecursion = isrecursion.values() === '1';
        const isDynamicCustom = isDynamic && operatorTypeValue === '3';
        const isResource = operatorTypeValue === '0';
        const isDept = operatorTypeValue === '1';
        const isSubCom = operatorTypeValue === '2';
        const isDynamicCustomRecursion = isDynamicCustom && isRecursion;
        const relationtypeValue = relationtype.values();
        const isPointNode = relationtypeValue === '0';
        const isRelateNode = relationtypeValue === '1';

        const relationtypeOptions = [];
        if (store.parentNodeType && store.parentNodeType === '0') {
            relationtypeOptions.push({
                key: '0',
                showname: getLabel('502725', '指定节点'),
            });
        } else {
            relationtypeOptions.push({
                key: '1',
                showname: getLabel('502726', '关联上级节点'),
            });
        }
        const operateTypeOptions = [];
        if (store.parentOperateType && store.parentOperateType === '0') {
            operateTypeOptions.push({
                key: '0',
                showname: getLabel(502300, '人力资源'),
            },{
                key: '3',
                    showname: getLabel(502465, '自定义'),
            });
        }else if(store.parentOperateType && store.parentOperateType === '1'){
            operateTypeOptions.push({
                key: '0',
                showname: getLabel(502300, '人力资源'),
            },{
                key: '1',
                showname: getLabel(502298, '部门'),
            },{
                key: '3',
                    showname: getLabel(502465, '自定义'),
            });
        }else if(store.parentOperateType && store.parentOperateType === '2'){
            operateTypeOptions.push({
                key: '0',
                showname: getLabel(502300, '人力资源'),
            },{
                key: '1',
                showname: getLabel(502298, '部门'),
            },{
                key: '2',
                    showname: getLabel(502299, '分部'),
            },{
                key: '3',
                    showname: getLabel(502465, '自定义'),
            });
        }else{
            operateTypeOptions.push(
            {
                key: '0',
                showname: getLabel(502300, '人力资源'),
            }, {
                key: '1',
                showname: getLabel(502298, '部门'),
            }, {
                key: '2',
                showname: getLabel(502299, '分部'),
            }, {
                key: '3',
                showname: getLabel(502465, '自定义'),
            });
        }
        return (
            <Dialog
                dialog={store}
                className="edc-path-node-modal"
            >
                <div className="edc-path-node-form">
                    <Row className="edc-addNode-item-row">
                        <Col span={24}>
                            <WeaFormItem
                                label={getLabel('502717', '节点名称')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['name'] })}
                            >
                                <WeaInput style={{ marginLeft: 10 }} viewAttr={3} {...nameField.bind()} />
                            </WeaFormItem>
                        </Col>
                    </Row>
                    <div className="edc-node-setting">
                        <div style={{ marginBottom: 5 }}>
                            <WeaTab
                                {...nodetype.bind()}
                                datas={nodetypeOptions}
                                keyParam="key"
                                selectedKey={nodeTypeValue}
                                onChange={store.changeNodeType}
                            ></WeaTab>
                        </div>
                        {isDynamic && <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502718', '解析类型')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}

                                >
                                    <WeaSelect
                                        className="edc-addNode-set-select"
                                        viewAttr={3}
                                        detailtype={3}
                                        options={operateTypeOptions}
                                        {...operatortype.bind()}
                                        onChange={store.changeOperatorType}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row>}
                        {isDynamicCustom && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502719', '自定义对象表名')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['tablename'] })}
                            >
                                <WeaInput viewAttr={3} {...tablename.bind()} />
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502720', '自定义对象主键')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['tablekey'] })}
                            >
                                <WeaInput viewAttr={3} {...tablekey.bind()} />
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502721', '自定义对象显示名称')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['showfield'] })}
                            >
                                <WeaInput viewAttr={3} {...showfield.bind()} />
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustom && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502722', '是否递归解析')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['isrecursion'] })}
                            >
                                <WeaCheckbox
                                    helpfulTip={getLabel('502722', '是否递归解析')}
                                    display="switch"
                                    style={{ display: 'inline' }}
                                    {...isrecursion.bind()}
                                />
                            </WeaFormItem>
                        </Row>}
                        {isDynamicCustomRecursion && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502723', '上级字段')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['tablesup'] })}
                            >
                                <WeaInput viewAttr={3} {...tablesup.bind()} />
                            </WeaFormItem>
                        </Row>}
                        {isDynamic && <Row className="edc-addNode-item-row">
                            <WeaFormItem
                                label={getLabel('502724', '关系类型')}
                                labelCol={{ span: 6 }}
                                wrapperCol={{ span: 8 }}
                                error={form.getError({ domkey: ['relationtype'] })}
                            >
                                <WeaSelect
                                    className="edc-addNode-set-select"
                                    viewAttr={3}
                                    detailtype={3}
                                    options={relationtypeOptions}
                                    // options={[{
                                    //     key: '0',
                                    //     showname: getLabel('502725','指定节点'),
                                    // }, {
                                    //     key: '1',
                                    //     showname: getLabel('502726','关联上级节点') ,
                                    // }]}
                                    {...relationtype.bind()}
                                />
                            </WeaFormItem>
                        </Row>}
                        {isDynamic && isPointNode && isResource &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmresource'] })}
                                >
                                    <WeaBrowser viewAttr={3} {...hrmresource.bind()} isSingle={false} type={17} title="选择人员" />
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamic && isPointNode && isDept &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmdepartment'] })}
                                >
                                    <WeaBrowser viewAttr={3} {...hrmdepartment.bind()} isSingle={false} type={57} title="选择部门" />
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamic && isPointNode && isSubCom &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502727', '指定对象')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['hrmsubcompany'] })}
                                >
                                    <WeaBrowser viewAttr={3} {...hrmsubcompany.bind()} isSingle={false} type={194} title="选择分部" />
                                </WeaFormItem>
                            </Row>
                        }
                        {isPointNode && isDynamicCustom &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502728', '指定id')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    error={form.getError({ domkey: ['rootids'] })}
                                >
                                    <WeaInput viewAttr={3} {...rootids.bind()} />
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamicCustom && isRelateNode &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502729', '上级节点字段')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 8 }}
                                    error={form.getError({ domkey: ['supnodefield'] })}
                                >
                                    <WeaInput viewAttr={3} {...supnodefield.bind()} />
                                </WeaFormItem>
                            </Row>
                        }
                        {isDynamicCustom && isRelateNode &&
                            <Row className="edc-addNode-item-row">
                                <WeaFormItem
                                    label={getLabel('502730', '本级节点字段')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 8 }}
                                    error={form.getError({ domkey: ['nodefield'] })}
                                >
                                    <WeaInput viewAttr={3} {...nodefield.bind()} />
                                </WeaFormItem>
                            </Row>
                        }
                        {/* <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502731','链接地址')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                    rules={'required|string'}
                                    error={form.getError({ domkey: ['hreflink'] })}
                                >
                                    <WeaSelect
                                        viewAttr={2}
                                        {...hreflinkType.bind()}
                                        options={[{
                                            key: '1',
                                            showname: getLabel('502732','表格页面'),
                                        }, {
                                            key: '2',
                                            showname: getLabel('502733','自定义页面'),
                                        }]}
                                        style={{ width: 100, marginRight: 10 }}
                                    />
                                    {hreflinkType.values() === '1' ?
                                        <WeaSelect
                                            {...hreflink.bind()}
                                            style={{ width: '60%', verticalAlign: 'middle' }}
                                        // options={cubePageOptions}
                                        /> : hreflinkType.values() === '2' ? <WeaInput  {...hreflink.bind()} style={{ width: '60%', verticalAlign: 'middle' }} />
                                            : null
                                    }

                                </WeaFormItem>
                            </Col>
                        </Row> */}
                        {/* <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502734','允许自行分配')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                >
                                    <WeaCheckbox
                                        helpfulTip={getLabel('502735','开启自行分配')}
                                        display="switch"
                                        style={{ display: 'inline' }}
                                        {...iscustom.bind()}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row> */}
                        <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502898', '填报时间')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}>
                                    <WeaInput
                                        //value={reporttime}
                                        //onChange={}
                                        style={{ width: 50, marginRight: 10 }}
                                        viewAttr={3}
                                        {...reporttime.bind()}
                                    ></WeaInput>
                                    <WeaSelect
                                        style={{ width: 50, display: 'inline-block' }}
                                        options={[{ key: "0", showname: getLabel('502659', '时') }, { key: "1", showname: getLabel('502660', '天') }, { key: "2", showname: getLabel('502661', '月') }]}
                                        //value={reporttimetype}
                                        //onChange={}
                                        viewAttr={2}
                                        {...reporttimetype.bind()}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row>
                        <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502736', '是否联合上报')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                >
                                    <WeaCheckbox
                                        helpfulTip={getLabel('502736', '是否联合上报')}
                                        display="switch"
                                        style={{ display: 'inline' }}
                                        {...reporttype.bind()}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row>
                        <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502900', '撤回方式')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}

                                >
                                    <WeaSelect
                                        className="edc-addNode-set-select"
                                        detailtype={3}
                                        //value={undotype}
                                        options={[{
                                            key: '0',
                                            showname: getLabel('502656', '禁止'),
                                        }, {
                                            key: '2',
                                            showname: getLabel('506821', '提交前'),
                                        }, {
                                            key: '1',
                                            showname: getLabel('506822', '查看前'),
                                        }]}
                                        {...undotype.bind()}
                                    //onChange={store.changeOperatorType}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row>
                        {/* <Row className="edc-addNode-item-row">
                            <Col span={24}>
                                <WeaFormItem
                                    label={getLabel('502737','是否允许退回')}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{ span: 18 }}
                                >
                                    <WeaCheckbox
                                        helpfulTip={getLabel('502737','是否允许退回')}
                                        display="switch"
                                        style={{ display: 'inline' }}
                                        {...isreject.bind()}
                                    />
                                </WeaFormItem>
                            </Col>
                        </Row> */}
                    </div>
                    {(isDynamic || isStatic) && <OperatorSet store={store} />}
                </div>
            </Dialog>
        )
    }
}